

#include "Avatar.h"



//default constructor to initialize all components
//and create sprite
Avatar::Avatar()
{
//initialize all stats
	Level = 1;
	MaxHP = 100; CurrentHP = 30;
	Exp = 0;
	CurrentAttack = MaxAttack = 40;
	CurrentDefense = MaxDefense = 50;
	MaxStamina = CurrentStamina = 70;
	Money = 0;
	MaxSpecial = 100;
	CurrentSpecial = 0;


}


//display player's stats to screen
void Avatar::DisplayStats()
{
	PA_OutputText(1, 10, 5, "HP:   %d/%d", CurrentHP, MaxHP);
	PA_OutputText(1, 10, 6, "Stamina:   %d/%d", CurrentStamina, MaxStamina);
	PA_OutputText(1, 10, 7, "Special:   %d/%d", CurrentSpecial, MaxSpecial);
	PA_OutputText(1, 10, 8, "Attack:   %d", CurrentAttack);
	PA_OutputText(1, 10, 9, "Defense:   %d", CurrentDefense);
	calculateCurrentStamina();
}

//calculates and returns players current hp in percent form
u16 Avatar::calculateCurrentHP()
{
	u16 percentHP;
	percentHP = (CurrentHP*1000)/MaxHP;
	return percentHP;
}

//calculates and returns players current stamina in percent form
u16 Avatar::calculateCurrentStamina()
{
	u16 percentStam;
	percentStam = (CurrentStamina*1000)/MaxStamina;
	return percentStam;
}

//calculates and returns players current special in percent form
u16 Avatar::calculateCurrentSpecial()
{
	u16 percentSpec;
	percentSpec = (CurrentSpecial*1000)/MaxSpecial;
	return percentSpec;
}

//decrement stamina and return whether or not player has enough
bool Avatar::staminaCheck(u16 s)
{
	//if player has enough stamina
	if((CurrentStamina - s) >= 0)
	{
		CurrentStamina -= s;
		return true;
	}
	else
		return false;
}


//increase stamina
void Avatar::increaseStamina(u16 s)
{
	//make sure you don't overflow the stamina guage
	if((CurrentStamina + s) >= MaxStamina)
	{
		CurrentStamina = MaxStamina;
	}
	else
		CurrentStamina += s;
}


//increase health
void Avatar::increaseHP(u16 h)
{
	//make sure you don't overflow the hp guage
	if((CurrentHP + h) >= MaxHP)
	{
		CurrentHP = MaxHP;
	}
	else
		CurrentHP += h;
}


//increase Special guage	
void Avatar::increaseSpecial(u16 sp)
{
	//make sure you don't overflow the special guage
	if((CurrentSpecial + sp) >= MaxSpecial)
	{
		CurrentSpecial = MaxSpecial;
	}
	else
		CurrentSpecial += sp;
}

//decrement special and return whether player has enough
bool Avatar::useSpecial(u16 sp)
{
	//if player has enough sp points
	if((CurrentSpecial - sp) >= 0)
	{
		CurrentSpecial -= sp;
		return true;
	}
	else
		return false;
}
	
	
//give temp attack boost
void Avatar::attackBoost(u16 a)
{
	CurrentAttack += a;
}

//check to see if player has an attack boost
bool Avatar::gotAttackBoost()
{
	if(CurrentAttack > MaxAttack)
		return true;
	else
		return false;
}
	
//give attack boost
void Avatar::incAttackBoost(u16 a)
{
	CurrentAttack += a;
}	

//decrement attack boost
void Avatar::decAttackBoost(u16 a)
{
	//make sure CurrentAttack does not go below MaxAttack
	if(gotAttackBoost())
	{
		CurrentAttack -= a;
	}
}
	
	
//give temp defense boost
void Avatar::defenseBoost(u16 d)
{
	CurrentDefense += d;
}

//check to see if player has a defense boost
bool Avatar::gotDefenseBoost()
{
	if(CurrentDefense > MaxDefense)
		return true;
	else
		return false;
}

//give defense boost
void Avatar::incDefenseBoost(u16 d)
{
	CurrentDefense += d;
}	

//decrement defense boost
void Avatar::decDefenseBoost(u16 d)
{
	//make sure CurrentAttack does not go below MaxAttack
	if(gotDefenseBoost())
	{
		CurrentDefense -= d;
	}
}

//calculates damage recieved and determines life status of player
bool Avatar::receiveDamage(u16 d)
{
	u16 temp = CurrentHP;
	if((temp -= d) <= 0)
	{
		CurrentHP = 0;
		return true; //dead
	}
	else
	{
		CurrentHP -= d;
		return false;
	}
	/*CurrentHP -= d; //decrease hp
	
	if(CurrentHP <= 0)
	{
		CurrentHP = 0; //make sure health does not go negative
		return true; //dead
	}
	else
		return false;//alive*/
}


void Avatar::defeatEnemy(u16 xp, u16 sp)
{
	Exp += xp;
	//add leveling up later
	
	if((CurrentSpecial + sp) >= MaxSpecial)
		CurrentSpecial = MaxSpecial;
	else
		CurrentSpecial += sp;
}

